@extends('layout.app')

@section('content')

    <div class="box-body">

        <table id="rowed3"></table>
        <div id="prowed3"></div>

    </div>

<script>

$(document).ready(function() {

	var data = {
        url :"/order/wx",
        postData: postData(),
        colNames: ['订单号' , '下单玩家id' , '昵称' , '下单时间' , '完成时间' , '<i class="fa fa-jpy"></i> RMB(元)' , '支付类型' , '订单状态' , '扩展信息'],
        colModel: [
            {
                name: 'wx_orders.id',
                key: true
            }, {
                name: 'user_id'
            }, {
                name:'nickname',
                sortable:false
            }, {
                name: 'create_time',
				formatter:'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'},
                searchoptions: {
                sopt: ['lt', 'le', 'gt', 'ge'],
                	dataInit : function (elem) {
                    	$(elem).datepicker({
                            dateFormat: 'yy-mm-dd',
                            monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                            dayNamesMin: ['日','一','二','三','四','五','六'] });
                	}
                }
            }, {
                name: 'finish_time',
                formatter:'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'},
                searchoptions: {
                    sopt: ['lt', 'le', 'gt', 'ge'],
                    dataInit : function (elem) {
                        $(elem).datepicker({
                            dateFormat: 'yy-mm-dd',
                            monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                            dayNamesMin: ['日','一','二','三','四','五','六'] });
                    }
                }
            }, {
                name: 'money',
                search: false
            },{
                name: 'pay_type',
                sortable: false,
                stype: 'select',
                searchoptions: {
                    sopt: ["eq", "ne"],
                    value: "1:银联;2:微信wap;3:微信扫码"
                },
                formatter: function(cellvalue) {
                    if (cellvalue) {
                        cellvalue = cellvalue.toString();
                    }
                    switch (cellvalue) {
                        case "1":
                            return '银联';
                        case "2":
                            return '微信wap';
                        case "3":
                            return '微信扫码';
                    }
                    return cellvalue;
                }
            }, {
                name: 'status',
                stype: 'select',
                searchoptions: {
                    sopt: ["eq", "ne"],
                    value: "0:下单;1:未回调;2:完成;3:取消;4:异常"
                },
                formatter: function(cellvalue, options, object) {
                    var id = object["wx_orders.id"];
                    cellvalue = cellvalue.toString();
                    switch (cellvalue) {
                        case "0":
                            return '下单';
                        case "1":
                            return '<span class="text text-danger">未回调</span>';
                        case "2":
                            return '<span class="text text-success">完成</span>';
                        case "3":
                            return '取消';
                        case "4":
                            return '<span class="text text-danger">异常</span>';
                    }
                    return "";
                }
            }, {
                name: 'desc',
                sortable: false,
                search: false
            }],
        caption: '<i class="fa fa-list"></i> {{$label2}}',
        sortname: 'wx_orders.id',
        sortorder: "desc",
        gridComplete: function() {
            $(this).footerData("set", {
                "money":"合计: " + $(this).getCol("money", false, "sum")
            });
        }
    };

	jqGrid(data);
});

function postData() {
    return {
        @if($request->get("user_id"))
        user_id: '{{$request->get("user_id")}}',
        @endif
        @if($request->get("status"))
        status: '{{$request->get("status")}}',
        @endif
    }
}

function check(id) {
    $.post("/order/wx/check",
        {id: id},
        function(data) {
            if (data.success) {
                jQuery('#rowed3').setGridParam({}).trigger('reloadGrid');
            }
            $.gritter.add({
                text: data.ret.trade_state_desc,
                sticky: false,
                time: '',
                class_name: 'gritter-light'});
        });
    return false;
}

</script>
@endsection